﻿using UnityEngine;
using UnityEngine.UI;

public class HPManager : MonoSingleton<HPManager>
{
    public int DeathTime = 5;
    private int curHitTime = 0;
    private SpriteRenderer spriteRenderer;

    // Start is called before the first frame update
    void Awake()
    {
        //spriteRenderer = GetComponent<SpriteRenderer>();
    }

    public override void Release()
    {
        DeathTime = 5;
        curHitTime = 0;
        base.Release();
    }

    public void OnPlayerHit()
    {
        curHitTime++;
        if (curHitTime == DeathTime)
        {
            curHitTime = 0;
            //spriteRenderer.color = Color.white;
            OnGameOver();
        }
        else
            spriteRenderer.color = new Color(1, 1, 1, ((DeathTime - curHitTime) / (float)DeathTime));
    }

    public void OnGameOver()
    {
        ScenesManager.Instance.SetGameStatus();
        ScenesManager.Instance.JumpToScene(ScenesManager.Scene.GameRoom); 
    }
}
